var app = new Vue({
    el: '#app',
    data: {
        host: host,
        username: '',
        sku: [],
        orders: [],
        create_time: '',


    },
    mounted: function () {
        // 获取个人信息
        // this.get_person();

        // 获取cookie中的用户名

        let u_json = $cookies.get('username')   //使用第三方库获取cookie
        let u_str = JSON.parse(u_json)    //将数据进行json反序列化
        this.username = eval(u_str)     //将unicode编码转为中文

        this.get_history()
    },
    methods: {
        get_history: function () {
            // 添加下列代码, 发送请求, 获取用户的全部订单信息:
            axios.get(this.host + '/myorders/', {
                responseType: 'json',
                withCredentials: true,
            })
                .then(response => {
                    //判断用户是否符合要求
                    if (response.data.code == 400) {
                        //next=是如果未登录要跳转的页面
                        location.href = 'login.html?next=' + location.href;
                        return
                    }

                    this.orders = response.data.oder_list;

                    for (var i = 0; i < this.orders.length; i++) {
                        console.log(this.orders[i].sku);
                        this.sku.push(this.orders[i].sku)

                    }



                })
                .catch(error => {
                    console.log(error)
                });
        },
        logoutfunc: function () {
            var url = this.host + '/logout/'
            axios.delete(url, {
                responseType: 'json',
                withCredentials: true,
            })
                .then(response => {
                    // console.log(response.data)
                    location.href = 'login.html'

                })
                .catch(error => {
                    console.log(error.response)
                })
        }

    }

})